package com.bosssoft.user.permission.center.serve.controller;

import com.bosssoft.user.permission.center.serve.api.UserApi;
import com.bosssoft.user.permission.center.serve.pojo.query.UserEntity;
import com.bosssoft.user.permission.center.serve.dao.entity.UserRoleInfo;
import com.bosssoft.user.permission.center.serve.pojo.query.UserQuery;
import com.bosssoft.user.permission.center.serve.pojo.vo.UserVo;
import com.bosssoft.user.permission.center.serve.service.UserService;
import common.annotation.ApiLog;
import common.data.commonresponse.CommonPage;
import common.data.commonresponse.CommonResponse;
import common.util.CommonResponseUtils;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
public class UserController implements UserApi {
    @Autowired
    private UserService userService;

    public CommonResponse<CommonPage<UserVo>> selectUserInfo(@RequestBody UserQuery userQuery){
        UserEntity userEntity = userQuery.getUserEntity();
        Integer page = userQuery.getPageIndex();
        Integer limit = userQuery.getPageSize();
        System.out.println(userQuery.getUserEntity().getTelephone());
        return CommonResponseUtils.success(userService.selectUserInfo(userEntity,page,limit));
    }

    public CommonResponse<CommonPage<UserEntity>> queryUserList(@RequestBody UserQuery userQuery){
        UserEntity userEntity = userQuery.getUserEntity();
        Integer page = userQuery.getPageIndex();
        Integer limit = userQuery.getPageSize();
        return CommonResponseUtils.success(userService.queryUserList(userEntity,page,limit));
    }

    public CommonResponse<Boolean> addUserInfo(@RequestBody UserEntity userEntity){
        return CommonResponseUtils.booleanResult(userService.addUserInfo(userEntity));
    }

    public CommonResponse<Boolean> modifyUserInfo(@RequestBody UserEntity userEntity){
        return CommonResponseUtils.booleanResult(userService.modifyUserInfo(userEntity));
    }

    public CommonResponse<Boolean> modifyUserStatus(@RequestBody UserEntity userEntity){
        return CommonResponseUtils.booleanResult(userService.modifyUserStatus(userEntity));
    }

    public CommonResponse<Boolean> deleteUsersByIds(@RequestBody List<String> ids){
        return CommonResponseUtils.booleanResult(userService.deleteUsersByIds(ids));
    }

    public CommonResponse<Boolean> startUsers(@RequestBody List<String> ids){
        return CommonResponseUtils.booleanResult(userService.startUsers(ids));
    }

    public CommonResponse<Boolean> shutUsers(@RequestBody List<String> ids){
        return CommonResponseUtils.booleanResult(userService.shutUsers(ids));
    }

    public CommonResponse<Boolean> deleteUserById(@RequestBody UserEntity userEntity){
        return CommonResponseUtils.booleanResult(userService.deleteUserById(userEntity));
    }

    public CommonResponse<Boolean> allocateCharacter(@RequestBody UserQuery userQuery){
        List<String> ids = userQuery.getIdsList();
        List<String> roleIds = userQuery.getRoleIdsList();
        String character = userQuery.getUserEntity().getUserCharacter();
        System.out.println(ids);
        System.out.println(character);
        System.out.println("000000000000000000000"+roleIds);
        //return CommonResponseUtils.booleanResult(userService.allocateCharacter(ids,character,roleId,roleCode));
        return CommonResponseUtils.booleanResult(userService.addUserRoleInfo(ids,roleIds));
    }

    public CommonResponse<CommonPage<UserRoleInfo>> selectRoleList(){
        return CommonResponseUtils.success(userService.selectRoleList());
    }

    /**
     * 获取资源树结构。
     *
     * @return 资源树结构的响应对象。
     */
    public CommonResponse<Object> getTree() {
        return CommonResponseUtils.success(userService.getTree());
    }
}
